package action;

import bean.Person;
import com.opensymphony.xwork2.Action;
import service.PersonService;

import java.util.List;

public class PersonAction implements Action {
    private PersonService personService;
    private Person person;
    private List<Person> persons;

    public PersonService getPersonService() {
        return personService;
    }

    public void setPersonService(PersonService personService) {
        this.personService = personService;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public List<Person> getPersons() {
        return persons;
    }

    @Override
    public String execute() {
        persons = personService.find();
        return persons != null ? SUCCESS : null;
    }

    public String add() {
        personService.add(person);
        return "add";
    }

    public String edit() {
        person = personService.find(person.getPersonId());
        return person != null ? "edit" : null;
    }

    public String modify() {
        personService.modify(person);
        return "modify";
    }

    public String remove() {
        personService.remove(person.getPersonId());
        return "remove";
    }
}
